home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 7 / PC World Interactive 7.iso / program / cprog.EXE / EXAMPLE.C < prev    next >
Text File  |  1980-01-10  |  6KB  |  118 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /* Example source code to check if this executable's logged CRC or filesize  */
  4. /* has changed.                                                              */
  5. /*                                                                           */
  6. /* Written by Chuck Gilmore - (C)Copyright 1988, Gilmore Systems             */
  7. /*                                               P.O. Box 3831               */
  8. /*                                               Beverly Hills, CA 90212 USA */
  9. /*                                                                           */
  10. /*                                               Voice (213) 275-8006        */
  11. /*                                               Data  (213) 276-5263        */
  12. /*                                                                           */
  13. /* Designed for Turbo C version 1.5                                          */
  14. /*                                                                           */
  15. /* Instructions:                                                             */
  16. /*                                                                           */
  17. /*   Small model:   tcc -ms example exeawars.obj                             */
  18. /*                  makaware example.exe                                     */
  19. /*                  example                                                  */
  20. /*                                                                           */
  21. /*   Medium model:  tcc -mm example exeawarm.obj                             */
  22. /*                  makaware example.exe                                     */
  23. /*                  example                                                  */
  24. /*                                                                           */
  25. /*   Large model:   tcc -ml example exeawarl.obj                             */
  26. /*                  makaware example.exe                                     */
  27. /*                  example                                                  */
  28. /*                                                                           */
  29. /*   Huge model:    tcc -mh example exeawarh.obj                             */
  30. /*                  makaware example.exe                                     */
  31. /*                  example                                                  */
  32. /*                                                                           */
  33. /*   Compact model: tcc -mc example exeawarc.obj                             */
  34. /*                  makaware example.exe                                     */
  35. /*                  example                                                  */
  36. /*                                                                           */
  37. /*                                                                           */
  38. /*  NOTE THE EXTRA STEPS FOR THE TINY MODEL:                                 */
  39. /*                                                                           */
  40. /*   Tiny model:    tcc -mt example exeawart.obj                             */
  41. /*                  exe2bin example.exe example.com                          */
  42. /*                  del example.exe                                          */
  43. /*                  makaware example.com                                     */
  44. /*                  example                                                  */
  45. /*                                                                           */
  46. /*****************************************************************************/
  47.  
  48. #include <stdio.h>
  49.  
  50. main(argc,argv)
  51. int argc;
  52. unsigned char **argv;
  53.    {
  54.    int result;
  55.    FILE *f;
  56.  
  57.    extern int exeaware();
  58.  
  59.    printf("\nAbout to check stored values ...\n\n");
  60.  
  61.    result=exeaware(argv[0]);     /* call with name of THIS program (argv[0]) */
  62.    switch(result)
  63.       {
  64.       case 1:
  65.               printf("Stored CRC doesn't match - program altered!\n");
  66.               break;
  67.       case 2:
  68.               printf("Stored filesize doesn't match - program altered!\n");
  69.               break;
  70.       case 3:
  71.               printf("Stored CRC and filesize don't match - program altered!\n");
  72.               break;
  73.       case 0:
  74.       default:
  75.               printf("No changes to CRC or filesize detected - program unaltered\n");
  76.               break;
  77.       }
  78.  
  79. /*****************************************************************************/
  80. /** NOW, Let's change the size of the file by adding a byte to the filesize **/
  81. /** This will change both the filesize and the CRC of the file.             **/
  82. /*****************************************************************************/
  83.  
  84.    printf("about to change filesize\n");
  85.    if(!(f=fopen(argv[0],"ab")))           /* open for "append, binary mode" */
  86.       {
  87.       printf("Error - Can't open \"%s\"\n",argv[0]);
  88.       exit(1);
  89.       }
  90.    putc(0,f);                             /* write out 1 byte */
  91.    fclose(f);                             /* close the file   */
  92.  
  93. /***************************************************************************/
  94. /* The following is duplicated code from above (for example purposes only) */
  95. /***************************************************************************/
  96.  
  97.    result=exeaware(argv[0]);     /* call with name of THIS program (argv[0]) */
  98.    switch(result)
  99.       {
  100.       case 1:
  101.               printf("Stored CRC doesn't match - program altered!\n");
  102.               break;
  103.       case 2:
  104.               printf("Stored filesize doesn't match - program altered!\n");
  105.               break;
  106.       case 3:
  107.               printf("Stored CRC and filesize don't match - program altered!\n");
  108.               break;
  109.       case 0:
  110.       default:
  111.               printf("No changes to CRC or filesize detected - program unaltered\n");
  112.               break;
  113.       }
  114.  
  115.    exit(0);
  116.    }
  117.  
  118.